/**
 * 
 */
package com.planner.core.vo;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.persistence.UniqueConstraint;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

/**
 * @author Sangharsh
 *
 */
@Entity
@Table(
        name="GRAPH_NODE", 
        uniqueConstraints=
            @UniqueConstraint(columnNames={"CODE"})
    )
@XmlRootElement(name="node")
@XmlAccessorType(XmlAccessType.FIELD)
public class GraphNode{

	@Id
	@GeneratedValue(strategy = GenerationType.SEQUENCE)
	@Column(name="ID")
	
	@XmlElement(name="id")
	protected Long id;
	
	@XmlElement(name="code")
	@Column(name="CODE")
	protected String code;
	
	@XmlElement(name="name")
	@Column(name="NAME")
	protected String name;
	
	@XmlElement(name="description")
	@Column(name="DESCRIPTION")
	protected String description;
	
	@XmlElement(name="active")
	@Transient
	protected boolean active;

	/**
	 * 
	 */
	private static final long serialVersionUID = 8335295701556541108L;

	public GraphNode(Long id, String code, String name,
			String description, boolean active) {
		assert (code != null) : "Code must not be null";
		assert (name != null) : "Name must not be null";
		assert (description != null) : "Description must not be null";

		this.id = id;
		this.code = code;
		this.name = name;
		this.description = description;
		this.active = active;
		
	}

	/**
	 * @return the id
	 */
	public Long getId() {
		return id;
	}

	/**
	 * @param id the id to set
	 */
	public void setId(Long id) {
		this.id = id;
	}

	/**
	 * @return the code
	 */
	public String getCode() {
		return code;
	}

	/**
	 * @param code the code to set
	 */
	public void setCode(String code) {
		this.code = code;
	}

	/**
	 * @return the name
	 */
	public String getName() {
		return name;
	}

	/**
	 * @param name the name to set
	 */
	public void setName(String name) {
		this.name = name;
	}

	/**
	 * @return the description
	 */
	public String getDescription() {
		return description;
	}

	/**
	 * @param description the description to set
	 */
	public void setDescription(String description) {
		this.description = description;
	}
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		return result;
	}
	
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		GraphNode other = (GraphNode) obj;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		return true;
	}

	public boolean isActive() {
		return active;
	}

	/**
	 * Constructs a <code>String</code> with all attributes
	 * in name = value format.
	 *
	 * @return a <code>String</code> representation 
	 * of this object.
	 */
	public String toString()
	{
	    final String TAB = "    ";
	    
	    String retValue = "";
	    
	    retValue = "GraphNode ( "
	        + super.toString() + TAB
	        + "id = " + this.id + TAB
	        + "code = " + this.code + TAB
	        + "name = " + this.name + TAB
	        + "description = " + this.description + TAB
	        + "active = " + this.active + TAB
	        + " )";
	
	    return retValue;
	}
	
}
